import java.util.*;

/**
 * @author LKQ
 * @date 2022/4/4 10:26
 * @description
 */
public class Solution2 {
    public static void main(String[] args) {

    }
    public int eraseOverlapIntervals(int[][] intervals) {
        if (intervals.length == 0) {
            return 0;
        }
        Arrays.sort(intervals, (o1, o2) -> o1[0] - o2[0]);
        int n = intervals.length;
        int left = intervals[0][1];
        int ans = 0;
        for (int i = 1; i < n; i++) {
            if (intervals[i][0] <= left) {
                ++ans;
                left = intervals[i][0];
            }
        }
        return ans;
    }
}
